package heima_design.model10;
/**
 * @ClassName: Singleton_solve
 * @Description: 解决反射破坏单例模式
 * @Version: v1.0.0
 * @Author: tang
 * @Date: 2022/06/02
 * Modification History:
 * Date             Author      Version     Description
 * -------------------------------------------------------------
 * 2022/06/02      tang        v1.0.0      创建
 */
public class Singleton_solve {
	private Singleton_solve(){
		/*
           反射破解单例模式需要添加的代码
        */
		if(instance != null) {
			throw new RuntimeException();
		}
	}
	private static volatile Singleton_solve instance;
	//对外提供静态方法获取该对象
	public static Singleton_solve getInstance() {
		
		if(instance != null) {
			return instance;
		}
		
		synchronized (Singleton.class) {
			if(instance != null) {
				return instance;
			}
			instance = new Singleton_solve();
			return instance;
		}
	}
}

